<template>
  <a-layout id="components-layout-demo-top" class="layout">
    <a-layout-header>
      <div class="logo" />
      <a-menu
        theme="dark"
        mode="horizontal"
        :default-selected-keys="['2']"
        :style="{ lineHeight: '64px' }"
      >
        <a-menu-item
          :key="menu.key"
          v-for="menu in menus"
          @click="onMenuClk(menu)"
        >
          <router-link :to="menu.link"></router-link>
          {{ menu.name | getChildProjectName(menu) }}
        </a-menu-item>
      </a-menu>
    </a-layout-header>
    <a-layout-content style="padding: 0">
      <div :style="{ background: '#fff', padding: '24px', minHeight: '280px' }">
        <router-view />
      </div>
    </a-layout-content>
  </a-layout>
</template>
<script>
import { aliveChildren } from '../core/child-projects-config'
export default {
  data() {
    return {
      collapsed: false,
      activeKey: 1, // 当前激活子应用
      menus: [
        // {
        //   name: "VIP汽运",
        //   key: 1,
        //   link: "/vipCar",
        // },
        // {
        //   name: "VIP基础设置",
        //   key: 2,
        //   link: "/vipBasic",
        // },
        // {
        //   name: "VIP铁运",
        //   key: 3,
        //   link: "/vipRailway",
        // },
        // {
        //   name: "货主PC",
        //   key: 4,
        //   link: "/ownerPc",
        // },
        // {
        //   name: "调度中心",
        //   key: 5,
        //   link: "/disCenter",
        // },
        {
          name: "交易平台",
          key: 6,
          link: "/tradePc",
        },
        // {
        //   name: "商户",
        //   key: 7,
        //   link: "/merchantPc",
        // },
      ],
    }
  },
  mounted() {console.log('main app');},
  computed: {},
  methods: {
    toggleCollapsed() {
      this.collapsed = !this.collapsed
    },
    onMenuClk(data) {
      this.activeKey = data.key
    },
  },
  filters: {
    getChildProjectName: (name, data) => {
      const arr = data.link.split('/')
      const link = arr[1] || arr[0]
      return !!aliveChildren[link] === true ? `${name}（保活）` : name
    },
  },
}
</script>
<style scoped>
#components-layout-demo-top-side-2 .handle-btn {
  width: 120px;
  height: 31px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px 28px 16px 0;
  float: left;
  cursor: pointer;
}
</style>
